package net.onceface.application.assembler;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import net.onceface.application.dto.AddressDTO;
import net.onceface.core.domain.Address;

public class AddressAssembler {

	public static AddressDTO toDTO(Address address){
		if(address == null){
			return null;
		}
		AddressDTO result = new AddressDTO();
		result.setId(address.getId());
		result.setVersion(address.getVersion());
		result.setDef(address.isDef());
		result.setAddress(address.getAddress());
		result.setPhone(address.getPhone());
		result.setName(address.getName());
		result.setClientId(address.getClientId());
		return result;
	}
	
	public static Address toEntity(AddressDTO address){
		if(address == null){
			return null;
		}
		Address result = new Address();
		result.setId(address.getId());
		result.setVersion(address.getVersion());
		result.setDef(address.isDef());
		result.setAddress(address.getAddress());
		result.setPhone(address.getPhone());
		result.setName(address.getName());
		result.setClientId(address.getClientId());
		return result;
	}
	
	public static List<Address>  toEntities(Collection<AddressDTO>  addresses){
		if (addresses == null) {
			return null;
		}
		List<Address> results = new ArrayList<Address>();
		for (AddressDTO each : addresses) {
			results.add(toEntity(each));
		}
		return results;
	}
	
	public static List<AddressDTO>  toDTOs(Collection<Address>  addresses){
		if (addresses == null) {
			return null;
		}
		List<AddressDTO> results = new ArrayList<AddressDTO>();
		for (Address each : addresses) {
			results.add(toDTO(each));
		}
		return results;
	}
}
